package com.ruoyi.quartz.task;

import com.ruoyi.ax.domain.AxGood;
import com.ruoyi.ax.service.IAxGoodService;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 定时任务调度测试
 * 
 * @author ruoyi
 */
@Component("goodPriceTask")
public class goodPriceTask
{
    private IAxGoodService iAxGoodService = SpringUtils.getBean(IAxGoodService.class);

    //更新商品价格和清0今日售卖数量
    public void goodPriceTaskHand() {
        List<AxGood> list = iAxGoodService.selectAxGoodList(new AxGood());
        for(AxGood axGood: list){
            if(axGood.getRoundId() ==null){
                continue;
            }
          Date begtime=   DateUtils.parseDate(axGood.getBeginYmd()+" 00:00:00");
            Date endtime=      DateUtils.parseDate( axGood.getEndYmd()+" 00:00:00");
            if(begtime.getTime()<System.currentTimeMillis() && System.currentTimeMillis() <endtime.getTime()){
                axGood.setTodaySellGoodCount("0");
                BigDecimal  todayPrice= new BigDecimal(axGood.getTodayPrice());
                BigDecimal topPrice= new BigDecimal(axGood.getTopPrice());
               // if(topPrice.compareTo(todayPrice)>0){
                    axGood.setBeforeYesterdayPrice(axGood.getYesterdayPrice());
                    axGood.setYesterdayPrice(todayPrice.setScale(2, RoundingMode.HALF_UP).toString());
                    BigDecimal  todayIncreasePrice= todayPrice.multiply(new BigDecimal(axGood.getDayIncreaseRate()).divide(new BigDecimal("100")));
                    todayPrice=todayPrice.add(todayIncreasePrice);
                    if(todayPrice.compareTo(topPrice)>0){
                        todayPrice=topPrice;
                    }
                    axGood.setTodayPrice(todayPrice.setScale(2,RoundingMode.HALF_UP).toString());
                    System.out.println("-----------------------");
                    iAxGoodService.updateAxGood(axGood);
               // }
            }


        }

    }





}
